<?php
/*
 * Created on 08.04.2007
 *
 * filename: fck_edit.php
 */
 
//ini_set("include_path",".:/var/www/");
//include("FCKeditor/fckeditor.php");
//
//$oFCKeditor = new FCKeditor('FCKeditor1');
//$oFCKeditor->BasePath = '/FCKeditor/';
//$oFCKeditor->Value = 'Default text in editor';
////$oFCKeditor->Config['CustomConfigurationsPath'] = '/myconfig.js' ;
//$oFCKeditor->Create();

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/** 
* Smarty function plugin (function.fckeditor.php)
* Requires PHP >= 4.3.0
* ------------------------------------------------------------- 
* Type:     function 
* Name:     fckeditor
* Version:  1.0
* Author:   gazoot (gazoot care of gmail dot com)
* Purpose:  Creates a FCKeditor, a very powerful textarea replacement.
* ------------------------------------------------------------- 
* @param InstanceName Editor instance name (form field name)
* @param BasePath optional Path to the FCKeditor directory. Need only be set once on page. Default: /FCKeditor/
* @param Value optional data that control will start with, default is taken from the javascript file
* @param Width optional width (css units)
* @param Height optional height (css units)
* @param ToolbarSet optional what toolbar to use from configuration
* @param CheckBrowser optional check the browser compatibility when rendering the editor
* @param DisplayErrors optional show error messages on errors while rendering the editor
*
* Default values for optional parameters (except BasePath) are taken from fckeditor.js.
*
* All other parameters used in the function will be put into the configuration section, 
* CustomConfigurationsPath is useful for example.
* See http://wiki.fckeditor.net/Developer%27s_Guide/Configuration/Configurations_File for more configuration info.
*/ 
require('function.fckeditor.php');

function smarty_function_yuitab($params, &$smarty)
{

	$content = $params['Content'];


	$p["BasePath"]	= '/fckeditor/';
//	$p["Value"]	= $params['Content'];

        $out = '';

        $out .= "<script type=\"text/javascript\">
YAHOO.example.init = function() {
    var tabView = new YAHOO.widget.TabView('demo');
};

YAHOO.example.init();
</script>";

        $out .= "<style type=\"text/css\">
#demo { width:820px; }
#demo .yui-content {
    padding:0.5em; /* pad content container */
}

</style>";
	$out .= "<div id=\"demo\" class=\"yui-navset\">";
	$out .= "<ul class=\"yui-nav\">";
	foreach($content as $c) {
		$s = ($c[1] == 'selected')?("class=\"selected\""):('');
		$out .= "<li $s><a href=\"#".$c[0]."\"><em>".$c[0]."</em></a></li>"; 
	}
	$out .= "</ul>";
	$out .= "<div class=\"yui-content\">\n";


	foreach($content as $c) {
//print_r($c);
		$out .= "<div id=\"".$c[0]."\">\n";

		foreach($c[content] as $item) {

			
			switch ($item[type]) {
				case    'textfield': 
					$out.= $item[label].": <input type=\"textfield\" name=\"$item[name]\" value=\"".$item[text]."\"><br>";
				break;				
				case    'textarea_fck': 
					$p['Value'] 		= $item[text];
					$p["InstanceName"]	= $item[Instance];
					$p["Height"]		= "500px";
					$p['BasePath']		= $item[BasePath];
					
					$out .= "<br>$item[label]";

					$out .= smarty_function_fckeditor($p, &$smarty);	
				break;
                                case    'label':
                                        $out .= "$item[label]: <b>$item[text]</b>";
                                break;

                                case    'iframe':
                                        $out .= "<p align=\"right\"><a href=\"$item[url]\" target=\"_blank\">открыть в новом окне</a></p>";
                                        $out .= "<iframe name=\"preview\" src=\"$item[url]\" width=\"800\" height=\"600\" hspace=\"5\" vspace=\"5\" align=\"center\"></iframe>";
                                break;
                                case    'checkbox':
                                        $f = ($item[enable])?(' checked'):('');
                                        $out .= "$item[label] <input type=\"checkbox\" value=\"$item[value]\" name=\"$item[name]\"$f><br>";
                                break;
                                case    'link':
                                        $align = ($item[align])?($item[align]):('left');
                                        $label = ($item[src])?("<img border=\"0\" src=\"$item[src]\" alt=\"[$item[label]]\" title=\"[$item[label]]\">"):($item[label]);
                                        $out .= "<div align=\"$align\"><a href=\"$item[href]\">$label</a></div>";
                                break;

                                
			}

		}
		$out .= "</div>\n";
	}
	$out .= "</div>";
	$out .= "</div>";        
        return $out;
} 

/* vim: set expandtab: */

 
?>
